package com.sec.android.app.myfiles.facade.cmd;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;

import com.sec.android.app.myfiles.dialog.NotEnoughStorageDialog;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.operation.FileOperator;

import org.puremvc.java.multicore.interfaces.INotification;
import org.puremvc.java.multicore.patterns.command.SimpleCommand;

import java.util.ArrayList;

/**
 * Created by sev_user on 2/22/2017.
 */
public class ShowNotEnoughStorageCmd extends SimpleCommand {
    private static final String TAG = "not_enough_storage";

    @Override
    public void execute(INotification notification) {
        Object[] params = (Object[]) notification.getBody();
        Context context = (Context) params[0];
        FragmentManager fm = (FragmentManager) params[1];
        ArrayList<FileRecord> recordList = (ArrayList<FileRecord>) params[2];
        String message = (String) params[3];
        FileOperator.Operation op = (FileOperator.Operation) params[4];

        NotEnoughStorageDialog dialog = NotEnoughStorageDialog.createInstance(context, recordList, message, op);
        if (fm != null) {
            FragmentTransaction ft = fm.beginTransaction();
            Fragment prev = fm.findFragmentByTag(TAG);
            if (prev != null) {
                ft.remove(prev);
            }

            if (ft != null) {
                ft.add(dialog, TAG);
                ft.commitAllowingStateLoss();
            }
        }
    }
}
